package com.nlelpct.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nlelpct.manage.mapper.SysVersionUpdateDetailMapper;
import com.nlelpct.manage.model.entity.SysVersionUpdateDetail;
import com.nlelpct.manage.service.ISysVersionUpdateDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author nlelpct
 * @since 2020-04-08
 */
@Service
@Slf4j
public class SysVersionUpdateDetailServiceImpl extends ServiceImpl<SysVersionUpdateDetailMapper, SysVersionUpdateDetail> implements ISysVersionUpdateDetailService {

    @Override
    public HashMap<String, List<SysVersionUpdateDetail>> getSysVersionUpdateDetailList(List<String> versionIds) {
        HashMap<String, List<SysVersionUpdateDetail>> versionUpdateInfoDetailMap = new HashMap<>();

        if (versionIds != null && versionIds.size() > 0) {

            QueryWrapper<SysVersionUpdateDetail> query = new QueryWrapper<>();
            query.in(SysVersionUpdateDetail.VERSION_ID, versionIds);
            List<SysVersionUpdateDetail> versionUpdateDetails = this.list(query);


            if (versionUpdateDetails != null && versionUpdateDetails.size() > 0) {
                for (String versionId: versionIds) {
                    List sysVersionUpdateDetailList = new ArrayList<>();
                    for(SysVersionUpdateDetail sysVersionUpdateDetailItem: versionUpdateDetails) {
                        if (sysVersionUpdateDetailItem.getVersionId().equals(versionId)) {
                            sysVersionUpdateDetailList.add(sysVersionUpdateDetailItem);
                        }
                    }
                    sysVersionUpdateDetailList.sort(Comparator.comparing(SysVersionUpdateDetail::getMsgOrder));
                    versionUpdateInfoDetailMap.put(versionId, sysVersionUpdateDetailList);
                }

            }

        }


        return versionUpdateInfoDetailMap;
    }
}
